<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="author" content="wangbo">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {      margin: 0px;
      padding: 0px;
    }
    table {
      width: 500px;
    }

    th,
    td {
      border: 1px solid #ccc;
      border-collapse: collapse;
    }

    img {
      width: 40px;
      height: 50px;
    }

    input {
      width: 20px;
    }

    tr td:nth-child(5) {
      color: red;
    }


  </style>
</head>

<body>
  <table cellpadding='0' cellspacing="0">
    <thead>
      <thead>
        <tr>
          <th>名称</th>
          <th>图片</th>
          <th>单价</th>
          <th>加减</th>
          <th>数量</th>
          <th>操作</th>
        </tr>
      </thead>
    <tbody>
    <tbody>
      <tr>
        <td>小米</td>
        <td><img src="http://p1.music.126.net/A4oyg7nydQk9na3fCE7ZDg==/109951165421617285.jpg?imageView&amp;quality=89">
        </td>
        <td>500</td>
        <td><button onclick="sub()">-</button><button onclick="add()">+</button></td>
        <td>1</td>
        <td>删除</td>
      </tr>
      <tr>
        <td>小米</td>
        <td><img src="http://p1.music.126.net/A4oyg7nydQk9na3fCE7ZDg==/109951165421617285.jpg?imageView&amp;quality=89">
        </td>
        <td>500</td>
        <td><button onclick="sub()">-</button><button onclick="add()">+++</button></td>
        <td>1</td>
        <td>删除</td>
      </tr>

      <tr>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td>总计 10086 </td>
      </tr>
    </tbody>
  </table>
  <script>
     var pic_arr = ["http://p1.music.126.net/A4oyg7nydQk9na3fCE7ZDg==/109951165421617285.jpg?imageView&quality=89",
      "http://p1.music.126.net/c27byhx3KVvCle1zykmH_A==/109951165421216056.jpg?imageView&quality=89",
      "http://p1.music.126.net/uU3uL1XvXk7UieISRivS2g==/109951165421640213.jpg?imageView&quality=89",
      "http://p1.music.126.net/Mot-Vbz3JxqI2zbLzye0lQ==/109951165421632886.jpg?imageView&quality=89",
      "http://p1.music.126.net/KLyKvFgCMO68juLWVCgD4A==/109951165421399234.jpg?imageView&quality=89"]

      let color_arr = ["red","green","blue","black","pink"]
      
      let i = 0;
      let add = function () {
        // 获取事件触发的元素
        let btn = event.target
        // 拿到btn 的父级的td
        let ftd = btn.parentElement
        // 图片的td ftd.previousElementSibling.previousElementSibling
        let tdimg = ftd.previousElementSibling.previousElementSibling;
        let img = tdimg.children[0] 
        // 每次点击下标+1
        i++;
        // 下标超过之后,从0开始
        if (i>pic_arr.length-1) {
          i= 0
        }
        img.src = pic_arr[i]
        // console.log(tdimg.children[0] ) 
        let numtd = ftd.nextElementSibling
        numtd.style.color = color_arr[i]
      }
      let sub = function () {
        // 获取事件触发的元素
        let btn = event.target
        // 拿到btn 的父级的td
        let ftd = btn.parentElement
        // 图片的td ftd.previousElementSibling.previousElementSibling
        let tdimg = ftd.previousElementSibling.previousElementSibling;
        let img = tdimg.children[0] 
        // 每次点击下标-1
        i--;
        if (i<0) {
          i = pic_arr.length-1
        }
        img.src = pic_arr[i]
        let numtd = ftd.nextElementSibling
        numtd.style.color = color_arr[i]
      }
  </script>


</body>

</html>